$(function () {
    //功能部分
    //处理顶部导航hover隐藏显示；
    function handlerTopleftOver() {
        $(this)
            .addClass("active")
            .find(".top-menu")
            // .css({
            //     display: 'block'
            // })
            .stop(true)
            .slideDown(100)
    }

    function handlerTopleftout() {
        $(this)
            .removeClass("active")
            .find(".top-menu")
            .css({
                display: 'none'
            })
    }

    //导航hover事件
    $(".ng-toolbar-left li").on("mouseenter", handlerTopleftOver)
    $(".ng-toolbar-left li").on("mouseleave", handlerTopleftout)




    // 为你推荐页面渲染
    // function getGoodsData() {
    //     let options = {
    //         data: { pagesize: 30 }
    //     }

    //     let def = $.ajax("http://localhost:8888/goods/list", options)
    //     def.done(renderGoodsData)
    // }
    // getGoodsData()

    // function renderGoodsData(data) {
    //     let { list } = data;
    //     console.log(data);
    //     let loadingsrc = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fupload-images.jianshu.io%2Fupload_images%2F2849764-3384bb74a457c83d.gif&refer=http%3A%2F%2Fupload-images.jianshu.io&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1671884775&t=4a5ae16a4bad6c48e2aa4b76bd4350db";

    //     $(".recommend-list").html(
    //         list.map(item => {
    //             console.log(item.img_big_logo);
    //             return `<div class="recommend-box">
    //                 <img class="lazyload" src="${loadingsrc}" data-src="${item.img_big_logo}" alt="">
    //                 </div>`
    //             // <img class="lazyload" src="${item.img_big_logo}" alt="">
    //         }).join("")
    //     )
    //     lazyload();
    // }



    // 重开 - 为你推荐页面渲染
    getGoodsData()
    function getGoodsData() {
        let options = {
            data: { pagesize: 30 }
        }
        return $.ajax("http://localhost:8888/goods/list", options)
    }

    function renderGoodsData(data) {
        let { list } = data;
        // console.log(data);
        let loadingsrc = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fupload-images.jianshu.io%2Fupload_images%2F2849764-3384bb74a457c83d.gif&refer=http%3A%2F%2Fupload-images.jianshu.io&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1671884775&t=4a5ae16a4bad6c48e2aa4b76bd4350db";

        $(".recommend-list").html(
            list.map(item => {
                // console.log(item.img_big_logo);
                return `<div class="recommend-box" data-id="${item.goods_id}">
                            <img class="lazyload" src="${loadingsrc}" data-src="${item.img_big_logo}" alt="">
                            <p>${item.title}</p>
                            <p class="price-box">
                            <span class="price">
                                <i>￥</i>
                                <em>${item.price}</em>
                            </span>
                            </p>
                        </div>`
            }).join("")
        )
        lazyload();
    }
    getGoodsData().done(renderGoodsData)

    // 分类二级菜单显示
    function handlerSortOver() {
        $(".sort-hover")
            .addClass("active")
            .stop(true)
            .slideDown(100)
    }
    function handlerSortOut() {
        $(".sort-hover")
            .removeClass("active")

    }
    $(".sort-list li").on("mouseenter", handlerSortOver)
    $(".sort-list li").on("mouseleave", handlerSortOut)


    //详情页跳转功能
    //
    function jumpToDetailPage() {
        location.href = "../../detail/detail.html#" + $(this).attr("data-id");
    }
    $(".recommend-list").on("click", ".recommend-box", jumpToDetailPage)


});


